package models

import (
	"gorm.io/gorm"
	"srv/basic/config"
)

type DriverInfo struct {
	gorm.Model
	UserId        int    `json:"user_id" gorm:"int;index"`
	RealName      string `json:"real_name" gorm:"type:varchar(10);index"`
	IdCard        string `json:"id_card" gorm:"type:varchar(18);comment:身份证"`
	LicenseNumber string `json:"license_number" gorm:"type:varchar(20);comment:车牌号"`
	LicenseUrl    string `json:"LicenseUrl" gorm:"type:varchar(300);comment:驾驶证图片"`
	Status        int64  `json:"status" gorm:"type:int;default:2;comment:1已审核 2待审核 3审核不通过"`
}

func (d *DriverInfo) TableName() string {
	return "driver_info"
}

func (d *DriverInfo) CheckStatus() error { //修改状态
	return config.DB.Model(&d).Where("id = ?", d.ID).Updates(&d).Error
}

func (d *DriverInfo) GetDriverInfoById(id int64) error { //根据id获取详细信息
	return config.DB.Where("id = ?", id).Limit(1).Find(&d).Error
}

func (d *DriverInfo) GetDriverInfoByIdLicenseNumber() error { //根据车牌号获取详细信息
	return config.DB.Where("license_number = ?", d.LicenseNumber).Find(&d).Error
}

func (d *DriverInfo) Create() error { //添加司机
	return config.DB.Create(&d).Error
}
